package org.jeecg.modules.orderDistributeLeafletsModule.controller;

import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.orderDistributeLeafletsModule.entity.sysuserOrderEntity;
import org.jeecg.modules.orderDistributeLeafletsModule.service.orderDistributeLeafletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/orderDistributeLeaflet")
public class orderDistributeLeafletController {

    @Autowired
    orderDistributeLeafletService service;

    /**
     * 将订单派单给供应商
     *
     * @param entity
     * @return
     */
    @PostMapping("/distributeOrdertoSysuser")
    public Result<?> distributeOrdertoSysuser(@RequestBody sysuserOrderEntity entity) {
        try {
            //将订单派单给供应商
            int count = service.distributeOrdertoSysuser(entity);
            //派给供应商后 修改订单状态改为已接单
            service.updateorderstatus(entity, entity.getOrderId(), entity.getOrderType());
            return Result.ok("派单成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("派单失败!");
        }

    }
}
